﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Persistent toolbars - jQuery Mobile Demos</title>
    <link href="../css/themes/default/jquery.mobile-1.4.2.min.css" rel="stylesheet" type="text/css" />
    <script src="../js/jquery.js" type="text/javascript"></script>
    <script src="../js/jquery.mobile-1.4.2.js" type="text/javascript"></script>
    <script src="../javescript/sessonuser.js" type="text/javascript"></script>
    <script>
        $(function () {
            $("[data-role='navbar']").navbar();
            $("[data-role='header'], [data-role='footer']").toolbar();
        });
        // 更新工具栏的内容
        $(document).on("pageshow", "[data-role='page']", function () {
            // Each of the four pages in this demo has a data-title attribute
            // which value is equal to the text of the nav button
            // For example, on first page: <div data-role="page" data-title="Info">
            var current = $(this).jqmData("title");
            // Change the heading
            $("[data-role='header'] h1").text(current);
            // Remove active class from nav buttons
            $("[data-role='navbar'] a.ui-btn-active").removeClass("ui-btn-active");
            // Add active class to current nav button
            $("[data-role='navbar'] a").each(function () {
                if ($(this).text() === current) {
                    $(this).addClass("ui-btn-active");
                }
            });
        });
    </script>
</head>
<body>
    <div data-role="header" data-position="fixed" data-theme="a">
        <a href="../" data-rel="back" class="ui-btn ui-btn-left ui-alt-icon ui-nodisc-icon ui-corner-all ui-btn-icon-notext ui-icon-carat-l">
            Back</a>
        <h1>
            Info</h1>
    </div>
    <!-- /header -->
    <div data-role="page" data-title="新建任务" class="jqm-demos">
        <div role="main" class="ui-content jqm-content jqm-fullwidth">
            <div>
                <label for="name">
                    名称:</label>
                <input type="text" name="name" id="name" placeholder="名称" data-clear-btn="true" />
            </div>
            <div>
                <label for="username">
                    金额:</label>
                <!--  <input type="number" data-clear-btn="false" id="txtPrice" value="0" />-->
                <input type="number" data-clear-btn="true" name="number" pattern="[0-9]*" id="number"
                    placeholder="0">
            </div>
            <div>
                <label for="remark">
                    备注:</label>
                <textarea cols="40" rows="8" name="remark" id="remark" placeholder="备注"></textarea>
            </div>
            <div>
                <label for="remark">
                    时间:</label>
                <textarea cols="40" rows="8" name="remark" id="Textarea1"></textarea>
                <script type="text/javascript">
                    $(function () {
                        var value = GetNowData();
                        $("#Textarea1").val(value);
                    });
                </script>
            </div>
            <div>
                <a data-role="button" id="submit" data-theme="b">提交</a>
                <script type="text/javascript">
                    $("#submit").click(function () {
                        var b = verify();
                        if (b) {
                            var username = Getusername();
                            alert(username);
                            var db = window.openDatabase("SugarDB", "1.0", "SugarDB", 5000000);
                            db.transaction(queryIB, errorIB, successIB);
                        }
                    });
                    // 查询数据库
                    function queryIB(tx) {
                        var name = document.getElementById("name").value;
                        var price = document.getElementById("number").value;
                        var details = document.getElementById("remark").value;
                        var datevalue = GetNowData();
                        var img = 0;
                        var InsertDataTableUserSql = "insert into  DATABILL (name,price,details,createtime,img) values(?,?,?,?,?)";
                        tx.executeSql(InsertDataTableUserSql, [name, price, details, datevalue, img]);
                    }
                    // 查询成功后调用的回调函数
                    function querySuccess(tx, results) {
                        if (results.rows.length != 0) {
                            var id = results.rows.item(results.rows.length - 1).id
                            var name = results.rows.item(0).name
                            var price = results.rows.item(0).price;
                            alert("查询OK" + id + "用处" + name + "价格" + price);
                        }
                    }
                    function errorIB(err) {
                        console.log("错误处理的SQL：" + err.code + "错误信息：" + err.message);
                        alert("错误信息：" + err.message);

                    }
                    // 事务执行成功后调用的回调函数
                    function successIB() {
                        alert("添加成功！");
                    }

                    function GetNowData() {
                        var s;
                        var myDate = new Date(); //时间
                        s = myDate.getFullYear() + "年";
                        s += (myDate.getMonth() + 1) + "月";
                        s += myDate.getDate() + "日";
                        return s;
                    }
                    //验证
                    function verify() {
                        var name = document.getElementById("name").value;
                        var price = document.getElementById("number").value;
                        var details = document.getElementById("remark").value;
                        if (name == "" || name == null) {
                            alert("名称不能为空！");
                            return false;
                        }
                        if (price == "" || price == null) {
                            alert("金额不能为空切金额只能是数字！");
                            return false;
                        }
                        if (isNaN(price)) {
                            alert("金额只能是数字！");
                            return false;
                        }
                        return true;
                    }
                </script>
            </div>
        </div>
    </div>
    <!-- /page -->
    <div data-role="footer" class="ui-body-b ui-body" data-position="fixed">
        <div data-role="navbar" data-iconpos="left">
            <ul>
                <li><a href="toolbarfixed.html" data-icon="edit" data-prefetch="true" data-transition="fade">
                    新建</a></li>
                <li><a href="tasklist.html" data-icon="grid" data-prefetch="true" data-transition="flip">
                    查看</a></li>
                <li><a href="dataManagement.html" data-icon="bullets" data-prefetch="true" data-transition="flip">
                    数据</a></li>
                <li><a href="setup.html" data-icon="gear" data-prefetch="true" data-transition="turn">
                    设置</a></li>
            </ul>
        </div>
        <!-- /navbar -->
    </div>
    <!-- /footer -->
</body>
</html>
